//
// Created by hanweiguang on 2019-02-16.
// Copyright (c) 2019 hanweiguang. All rights reserved.
//

#import "BookCell.h"
#import "BookModel.h"
#import "MASConstraintMaker.h"
#import "UIColor+extension.h"
#import "View+MASShorthandAdditions.h"

#pragma mark   创建书籍的cell

@implementation BookCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        [self settingViewAutoLayout];
    }
    return self;
}


#pragma mark   创建View

- (void)createView {

    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.text = @"标题设置";
    [self.contentView addSubview:self.nameLabel];

//    self.prcieLabel = [[UILabel alloc] init];
//    [self.contentView addSubview:self.prcieLabel];



    self.descLabel = [[UILabel alloc] init];
    self.descLabel.text = @"介绍信息设置,测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试";
    [self.contentView addSubview:self.descLabel];


    self.bookImageView = [[UIImageView alloc] init];  // 创建imageView对象
    self.bookImageView.center = self.contentView.center;  // 让图片在中间位置显示
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image_aa" ofType:@"png"];  // 获取图片资源所在路径
    self.bookImageView.image = [UIImage imageWithContentsOfFile:imagePath];  // 加载图片

    [self.contentView addSubview:self.bookImageView];


}

#pragma mark   定位布局

- (void)settingViewAutoLayout {


    int magin = 4;
    int padding = 10;

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.mas_equalTo(self.contentView).offset(padding);    // 设置titleLabel上边跟左边与父控件的偏移量
        make.right.mas_equalTo(self.contentView.mas_right).offset(-padding); // 设置titleLabel右边与父控件的偏移量

    }];


    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.nameLabel);                       // 设置contentLabel左边和右边对于titleLabel左右对齐
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(magin);     // 设置contentLabel的上边对于titleLabel的下边的偏移量
    }];

    [self.bookImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);                        // 设置contentImageView的左边对于titleLabel的左边对齐
        make.top.mas_equalTo(self.descLabel.mas_bottom);   // 设置contentImageView的上边对于contentLabel的下面的偏移量
        make.width.and.height.equalTo(100);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-magin); // 设置userLabel的下边对于父控件的下面的偏移量

    }];


}


#pragma mark   设置数据

- (void)config:(BookModel *)model {
//    self.bookImageView.image = [UIImage imageNamed:model.icon];
//    self.nameLabel.text = model.name;
//    self.prcieLabel.text = model.price;
//    self.descLabel.text = model.detail;
}


@end